<template>
    <view>
        <view class="pd mt110 ">
			<!-- <view class="fz24 cf pl40"  v-if="type==1">
				注：开锁键双击触发热车功能。
			</view> -->
        	<view class="kjhxerttwr ov fz32 cf row" v-if="type==2">
        		<view class="col">
        			解防状态（已开）
        		</view>
				<view class="">
					<switch :checked="xuan"  @change="onSwitchChange"/>
				</view>
        	</view>
			
			<view class="row cen mt100">
				<view class="col">
					<view class="fz30 cf" v-if="type==2">
						解防时长
					</view>
					<view class="fz30 cf" v-if="type==1">
						热车时长
					</view>
						<picker-view v-if="isdf" class="erertter" indicator-style="height: 60px;" indicator-class="kkjjdert"  :value="value" @change="jhhbeert"   @touchmove="handletouchmove">
							<picker-view-column>
								  <view class="dfytysert  fz50" :class="xzsd==index?'cf':'z9'" v-for="(item,index) in 60" :key="index" v-if="type==1">
									{{item}} min
								  </view>
								  <view class="dfytysert  fz50" :class="xzsd==index?'cf':'z9'" v-for="(item,index) in jfinfo" :key="index" v-if="type==2">
								  									{{item}}
								  </view>
							</picker-view-column>
						</picker-view>
				</view>
				<view class="col">
					<view class="khhnhxer" v-for="(sd,idx) in 13" :key="idx">
						
					</view>
				</view>
			</view>
        </view>
    </view>
</template>
<script>
    export default {
        data() {
            return {
				type:1,// 1热车时长设置 2解防模式
				isdf:false,
				value:[],
				xzsd:3,
				kjjser:[13,14,15,16,17,18,19,20,21,22,23,24,25],
				jfinfo:['15分钟','30分钟','1小时','2小时','4小时','8小时','长期'],
				jftime:['15','30','60','120','240','480','10000'],
				xuan:true,
				setjftime:0,
				carid:"",//车辆id
				sid:""//车辆状态的id
			}
        },
        components: {},
        methods: {
			onSwitchChange(e){	
				
				this.xuan=e.detail.value
			},
			jhhbeert(e){		
				this.xzsd=e.detail.value[0]	
				if(this.type == 2){
					let logs = e.detail.value[0]	
					this.setjftime =this.jftime[logs]
				}
			},
			handletouchmove(){
				uni.vibrateShort({
				    success: function () {
				    }
				});
			},
			async duration(time,disarm = 0){
				var params={}
				params.id=this.sid
				if(this.type==1){
					params.hot_time=time
				}else{
					params.disarm_val=time
					params.disarm=disarm
				}
				// var shichang=await this.get("/api/change/"+this.carid,params,"PUT")
				var shichang=await this.get("/api/change",params,"PUT")
				
				// uni.navigateBack({
				// 	delta:1
				// })
			}
		},
		onNavigationBarButtonTap(e) {
			let th = this			
			if(this.type == 1){
				// this.sendTimeCom('Cmd_Start_Up',this.xzsd)
				// 1热车时长设置 2解防模式
				this.duration(this.xzsd+1)
				let params = {isset:true,time:this.xzsd+1}
				uni.setStorageSync('hotcar',params)
			}else{
				// this.sendTimeCom('Cmd_Out_Alarm',this.xzsd)
				if(this.xuan){
					this.duration(this.xzsd+1,1)
				}else{
					this.duration(this.xzsd+1,0)
				}	
				let params = {isset:th.xuan,time:this.setjftime,keys:this.xzsd+1}
				uni.setStorageSync('jiefang',params)
			}
			uni.showToast({
				title:'已设置',
				icon:"none"
			})
			setTimeout(function(){
				uni.navigateBack({
					delta:1
				})
			},2000)
			
		},
		onLoad(e) {
			console.log("得到传来的参数",e)
			
			this.isdf = true
			let jhhde = ''
			this.type = e.type
			this.carid=e.id
			this.sid=e.sid
			if (e.type == 1){ // 1热车时长设置
				jhhde='热车时长设置'
				let jiefang = uni.getStorageSync('hotcar')
				console.log(jiefang);
				if(jiefang.hasOwnProperty('isset')){
					this.xzsd = jiefang.time-1
				}
				uni.showModal({
					title:"使用提示",
					showCancel:false,
					confirmText:"我已了解",
					content:"例如：您选择设置了5分钟热车时长，当车辆处于启动状态时，5分钟之内没有其他任何操作时，小科同学会判定您已经离开了车辆，时间一到，车辆会自动熄火"
				})
			}
			if (e.type == 2){ // 2解防模式
				jhhde='解防模式'
				let jiefang = uni.getStorageSync('jiefang')
				console.log(jiefang);
				if(jiefang.hasOwnProperty('isset')){
					this.xzsd = jiefang.keys-1
					this.setjftime = jiefang.time
					this.xuan = jiefang.isset
				}
				uni.showModal({
					title:"温馨提示",
					showCancel:false,
					confirmText:"我已了解",
					content:"当您需要车辆门锁在一定时间段内一直处于开启状态时，解防模式可以帮助到您。第一步：打开开启按钮；第二步：选择解防时间；第三步：点击门锁开启键。注：解防时间一过，车辆门锁自动关闭"
				})
			}
			this.value[0]=this.xzsd
			// console.log(uni.getStorageSync('jiefang'));
			uni.setNavigationBarTitle({
				title:jhhde
			})
		},
		// onNavigationBarButtonTap() {
		// 	uni.navigateBack({
		// 		delta:1
		// 	})
		// },
        mounted() {
			
		}
    }

</script>
<style  scoped>
	.kjhxerttwr{
		height: 140upx;
		background: #353C51;
		border-radius:12upx;
		padding-left: 76upx;
		line-height: 140upx;
	}
	.khhnhxer{
		background: #06639F;
		width: 60upx;
		height: 8upx;
		margin: auto;
		margin-top: 50upx;
		border-radius: 13upx;
	}
	.khhnhxer:nth-child(3),.khhnhxer:nth-child(4),.khhnhxer:nth-child(5),.khhnhxer:nth-child(9),.khhnhxer:nth-child(10),.khhnhxer:nth-child(11){
		width: 100upx;
	}
	.khhnhxer:nth-child(6),.khhnhxer:nth-child(8){
		width: 140upx;
	}
	.khhnhxer:nth-child(7){
		width: 180upx;
	}
	.erertter{
		margin-top: 60upx;
		height: 600upx;
	}
	.dfytysert{
		line-height: 120upx;
	}
</style>
